import request from './request';

const SIGN_IN = 'auth/signin';
const SIGN_UP = 'auth/signup';

export function signup(username, password) {
    const data = {
        username,
        password
    }
    // console.log('data :>> ', data);
    // return request.post(SIGN_UP, data);
    return new Promise((resolve,reject)=>{
        const res =request.post(SIGN_UP,data);
        res.then((resObj)=>{
            resolve(resObj);
        })
        
    })
}
export function login(username, password){
    const data = {
        username,
        password
    }
    
    return new Promise((resolve, reject) => {
        const result = request.post(SIGN_IN,data);
        // const status = result.
        console.log('result instanceof Promise :>> ', result instanceof Promise);
        console.log('data instanceof Promise :>> ', data instanceof Promise);
        if(result instanceof Promise){
            result.then((resultObj)=>{
                console.log('resultObj :>> ', resultObj);
                // return resultObj;
                resolve(resultObj);
            })
        }
    })
    // console.log('re sult :>> ', result);
    // try {
    //     result.then((value) => {
    //         console.log('value :>> ', value);

    //     })
    // } catch (error) {
    //     console.log('error :>> ', error);
    // }
    // result.then((value) => {
    //     console.log('value :>> ', value);
    // }).finally(error => {
    //     console.log('error :>> ', error);
    // })
}